﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TugasAkhir.Models;
using TugasAkhir.Objects;

namespace TugasAkhir
{
    public partial class GantiPassword : System.Web.UI.Page
    {
        DosenObject dosen;
        MahasiswaObject mahasiswa;

        protected void Page_Load(object sender, EventArgs e)
        {
            CheckSession();
        }

        private void CheckSession()
        {
            if (Session["id_role"] != null && Session["id_role"].ToString().StartsWith("RL"))
            {
                if (Session["id_role"].ToString() == "RL01")
                {
                    MahasiswaModel.GetMahasiswaDetail(Session["username"].ToString(), out this.mahasiswa);
                    this.litName.Text = mahasiswa.Nama;
                }
                else
                {
                    DosenModel.GetDosenDetail(Session["username"].ToString(), out this.dosen);
                    this.litName.Text = dosen.NamaDosen;
                }
            }
            else
            {
                Response.Redirect("/Login.aspx");
            }
        }

        protected void btSubmit_Click(object sender, EventArgs e)
        {
            bool flag = false;
            if (PenggunaModel.CekPasswordLama(Session["username"].ToString(), tbPasswordLama.Text))
            {
                flag = true;
            }

            if (flag)
            {
                if (tbPasswordBaru.Text == tbPasswordBaruUlang.Text)
                {
                    if (PenggunaModel.GantiPassword(Session["username"].ToString(), tbPasswordBaru.Text))
                    {
                        System.Diagnostics.Debug.WriteLine("BERHASIL");
                    }
                }
            }
        }

        protected void lnkLogout_Click(object sender, EventArgs e)
        {
            Session["id_role"] = "";
            Session["username"] = "";
            CheckSession();
        }
    }
}